package server.java.autoduel.Locations;

import java.awt.Point;
import java.io.Serializable;
import java.sql.Time;

import server.java.autoduel.Network.IPacketizable;

import com.sun.sgs.app.AppContext;
import com.sun.sgs.app.ManagedObject;

/**
 * Represents an abstract idea a location in the autoduel world
 * 
 * @author Ian Axelrod
 * @author Liz Ha
 * @author Andrew Muldowney
 * @author Edward Futch
 */
public abstract class Location implements Serializable, ManagedObject,
		IPacketizable {
	private static final long serialVersionUID = 4725219503652101007L;

	/**
	 * The name of the location
	 */
	protected String name;

	/**
	 * The time the location opens
	 */
	protected Time hourOpen;

	/**
	 * The time the location closes
	 */
	protected Time hourClose;

	/**
	 * The location of the location on the game map
	 */
	protected Point coords;

	/**
	 * Constructs a location
	 */
	public Location() {
	}

	/**
	 * Constructs a location
	 * 
	 * @param name
	 *            the name of the location
	 * @param hourOpen
	 *            the hour the location is opens
	 * @param hourClose
	 *            the hour the location closes
	 * @param coords
	 *            the location of the location on the game map
	 */
	public Location(String name, Time hourOpen, Time hourClose, Point coords) {
		this.name = name;
		this.hourOpen = hourOpen;
		this.hourClose = hourClose;
		this.coords = coords;
	}

	/**
	 * @return the coords
	 */
	public Point getCoords() {
		return this.coords;
	}

	/**
	 * @return the hourClose
	 */
	public Time getHourClose() {
		return this.hourClose;
	}

	/**
	 * @return the hourOpen
	 */
	public Time getHourOpen() {
		return this.hourOpen;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * All locations use this function to set their various members not set by
	 * XML files
	 */
	public abstract void loadMembers();

	/**
	 * @param coords
	 *            the coords to set
	 */
	public void setCoords(Point coords) {
		this.coords = coords;
	}

	/**
	 * @param hourClose
	 *            the hourClose to set
	 */
	public void setHourClose(Time hourClose) {
		AppContext.getDataManager().markForUpdate(this);
		this.hourClose = hourClose;
	}

	/**
	 * @param hourOpen
	 *            the hourOpen to set
	 */
	public void setHourOpen(Time hourOpen) {
		AppContext.getDataManager().markForUpdate(this);
		this.hourOpen = hourOpen;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		AppContext.getDataManager().markForUpdate(this);
		this.name = name;
	}
}